package cn.git.bbs.core.controller;

import cn.git.bbs.core.bean.product.Color;
import cn.git.bbs.core.bean.product.Product;
import cn.git.bbs.core.bean.product.Sku;
import cn.git.bbs.core.service.cms.CmsService;
import cn.git.bbs.core.service.sku.SkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Controller
public class ProductDetailController {

    @Autowired
    private CmsService cmsService;
    @Autowired
    private SkuService skuService;
    @RequestMapping(value = "/product/toProduct")
    public String toProduct(Long id, Model model){

        Product p =  cmsService.selectProductById(id);
        model.addAttribute("product",p);

        List<Sku> skus =  cmsService.selectSkuList(id);
        Set<Color> colors = new HashSet<Color>();
        for (Sku sku : skus) {
            Color color = sku.getColor();
            colors.add(color);
        }
        model.addAttribute("colors",colors);
        return "portal/product";
    }
}
